home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
prog
/
cfuncs.zip
/
CPYFIL.C
< prev
next >
Wrap
Text File
|
1991-08-01
|
1KB
|
79 lines
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <alloc.h>
#include <string.h>
int cpyfil(char *n1, char *n2)
{
#if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
unsigned long free_mem;
#else
unsigned free_mem;
#endif
unsigned block_size;
long file_size;
char *buf;
int f1, f2;
char mes[50];
if ( (f1 = open(n1, O_RDONLY | O_BINARY )) == -1)
{
strcpy(mes, n1);
message( strcat( mes, " NOT FOUND"), 2);
return(1);
}
if ( (f2 = open(n2, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, S_IWRITE )) == -1)
{
strcpy(mes, n2);
message( strcat( mes, " COULD NOT OPEN"), 2);
return(2);
}
free_mem = coreleft();
if((file_size = filelength(f1))==-1)
return(3);
block_size = min(0xFFF0, min(free_mem, file_size));
if((buf = malloc(block_size))==NULL)
return(4);
while (file_size > 0)
{
block_size = min(0xFFF0, min(free_mem, file_size));
if(read(f1, buf, block_size) == -1)
return(5);
if(write(f2, buf, block_size) == -1)
return(6);
file_size -= block_size;
}
free(buf);
close(f1);
close(f2);
return(0);
}
/*
#include <time.h>
main()
{
clock_t start, end;
start = clock();
cpyfil("\\tc\\tc.exe", "tc.exe");
end = clock();
printf("time was %f\n", (end-start) / CLK_TCK);
} */